package com.ocom.webapi.controller;

import com.ocom.common.constant.WebApiServiceUrl;
import com.ocom.common.entity.payconfig.EntityDishesFoodstuff;
import com.ocom.common.entity.payconfig.EntityFoodstuffInfo;
import com.ocom.common.request.payconfig.food.FoodClassIdRequest;
import com.ocom.common.request.payconfig.food.FoodstuffIdRequest;
import com.ocom.common.request.payconfig.food.GetDishesStuffListRequest;
import com.ocom.common.request.payconfig.food.GetFoodstuffListRequest;
import com.ocom.common.resp.Result;
import com.ocom.webapi.feign.PayConfigClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@PreAuthorize("@pms.hasRole('ROLE_WEB')" )
public class FoodstuffPageController {

    @Autowired
    PayConfigClientService payConfigClientService;

    //6.2.1食材列表（FoodstuffPage/onShow）
    @PostMapping(WebApiServiceUrl.Url_FoodstuffPageOnShow)
    public Result onShow(@RequestBody GetFoodstuffListRequest request) {

        if(request.getFoodClassId()!=0){
            FoodClassIdRequest foodClassIdRequest =new FoodClassIdRequest();
            foodClassIdRequest.setComId(request.getComId());
            foodClassIdRequest.setMerchId(request.getMerchId());
            foodClassIdRequest.setFoodClassId(request.getFoodClassId());
            Result result = payConfigClientService.getSubFoodClassList(foodClassIdRequest);
            if(result.getCode()==200){
                request.setClassIds((String) result.getData());
            }
        }
        return payConfigClientService.getFoodstuffList(request);
    }

    //6.2.2删除食材（FoodstuffPage/delete）
    @PostMapping(WebApiServiceUrl.Url_FoodstuffPageDelete)
    public Result delete(@RequestBody FoodstuffIdRequest request) {
        return payConfigClientService.removeFoodstuff(request);
    }

    //6.2.3添加食材（FoodstuffPage/add
    @PostMapping(WebApiServiceUrl.Url_FoodstuffPageAdd)
    public Result add(@RequestBody EntityFoodstuffInfo entityFoodstuffInfo) {
        return payConfigClientService.newFoodstuff(entityFoodstuffInfo);
    }

    //6.2.4修改食材（FoodstuffPage/modify）
    @PostMapping(WebApiServiceUrl.Url_FoodstuffPageModify)
    public Result modify(@RequestBody EntityFoodstuffInfo entityFoodstuffInfo) {
        return payConfigClientService.updateFoodstuff(entityFoodstuffInfo);
    }

    //6.2.5菜品食材列表（FoodstuffPage/dishesStuff）
    @PostMapping(WebApiServiceUrl.Url_FoodstuffPageDishesStuff)
    public Result dishesStuff(@RequestBody GetDishesStuffListRequest request) {
        return payConfigClientService.getDishesStuffList(request);
    }

    //6.2.6保存菜品食材含量（FoodstuffPage/savePart）
    @PostMapping(WebApiServiceUrl.Url_FoodstuffPageSavePart)
    public Result savePart(@RequestBody EntityDishesFoodstuff request) {
        return payConfigClientService.setDishesStuff(request);
    }

    //6.2.7删除菜品食材含量（FoodstuffPage/deletePart）
    @PostMapping(WebApiServiceUrl.Url_FoodstuffPageDeletePart)
    public Result deletePart(@RequestBody EntityDishesFoodstuff entityDishesFoodstuff) {
        return payConfigClientService.removeDishesStuff(entityDishesFoodstuff);
    }
}
